package com.abo.yaas.view.widgets;

import com.abo.yaas.i18n.Lang;
import com.abo.yaas.i18n.LocaleChangeListener;
import com.abo.yaas.i18n.LocaleChangedEvent;
import com.vaadin.ui.Label;

@SuppressWarnings("serial")
public class LocaleSensitiveLabel extends Label implements LocaleChangeListener {
    private String translationId = "";

    public LocaleSensitiveLabel(String translationId) {
        this(translationId, "");
    }

    public LocaleSensitiveLabel(String translationId, String content) {
        super(content, Label.CONTENT_XHTML);
        setSizeUndefined();
        this.translationId = translationId;
        Lang.addListener(this);
    }

    @Override
    public Class<?> getType() {
        return super.getType();
    }

    @Override
    public void localeChanged(LocaleChangedEvent event) {
        requestRepaint();
    }

    @Override
    public String toString() {
        return Lang.getMessage(translationId, super.toString());
    }
}
